package com.gy.paidao.util;

import com.gy.paidao.bean.BaseBean;
import com.squareup.okhttp.Response;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

/**
 * 作者：gy on 16/5/10
 * 说明：
 */
public class ParseBase {

    public static BaseBean parseBase(Response response){
        BaseBean baseBean = new BaseBean();
        try {
            String json = response.body().string();
            LogUtil.e(json);
            JSONObject object = new JSONObject(json);
            baseBean.success = object.optBoolean("success");
            baseBean.data = object.opt("data");
            baseBean.errCode = object.optString("errCode");
            baseBean.errMsg = object.optString("errMsg");
            baseBean.intData = object.optInt("data");
            baseBean.strData = object.optString("data");

        } catch (JSONException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return baseBean;
    }

}
